Okay, so in today's lesson we are going to start looking at local scripts.
Okay.
So local scripts are again very similar to your standard server scripts that we've been we've been looking
at for the last few lessons.
Um, but there are some key differences with it.
Um, the first off being um, where you can put local scripts.
Now, if you've experimented with local scripts already and you've put them in the workspace, they
will not work.
Okay.
Local scripts do not go into the workspace.
Local scripts can go into anything starting with starter.
So starter.
Starter pack and starter player.
Local scripts can go inside.
They can also go in replicated first.
Okay, so they are the locations that local scripts can be put inside.
And if you open up starter player you've got starter.
Starter character scripts and starter player scripts, which both can have local scripts inside of them.
Now before we start to talk about how all these things work, let's play the game and have a look at
what goes on in the explorer when you play the game.
So my character loaded in here and we're going to talk a bit about the player and the character.
Okay.
Um, so if we look inside a workspace, you will have all of your game objects and you'll also have
a model which is which.
The name of the model is the is the character's name or the player's name.
So this model contains the character for your player.
And if you open up that, you have a couple of objects.
Um, you have, um, its shirts, its clothing, its accessories here.
And you also have all of its body parts, along with some scripts that help script and animate scripts.
And a humanoid, a humanoid root part is all quite a lot going on here.
Okay.
Um.
I'll.
I'll point out the main things, but you will become a lot more confident with characters as you go
along.
Scripting.
So the humanoid is an essential part of a character.
Okay.
A humanoid is an object you add in, which basically without it, your character is just a block of
parts.
Okay.
The humanoid is what turns a block of parts into a character.
Okay, and these objects here are all very important as well as they are your body parts that you can
actually change their properties, which have a look at how to do today.
Okay.
So that's the first sight.
Her first half of your character.
Um, but you also have your player.
Now your player will exist in Gameplayers over here.
My player here.
If I open this up, I have a couple of things.
I have my backpack, I have starter gear, I have player UI and I have player scripts.
Okay.
And, um, player scripts already has some scripts there.
But basically what happens in the simplest way to explain it okay.
Is anything you put inside of starter starter player scripts will actually, um, will actually be put
inside of player scripts.
So anything inside starter player scripts gets duplicated over into player scripts when you join the
game.
The same thing happens with starter guy.
Anything inside starter guy will get duplicated and moved over to player guy.
Um, now the reason for this, which we will explain in a bit more detail later on in the course.
Um, but imagine if you have a inventory guy, okay.
And you want this to open when the player presses certain button.
Okay, that can all be scripted, but it wouldn't work if you just had one object for the inventory,
because if you had one guy object for the inventory, um, and you turned enabled on.
So you made the guy visible, it'd be visible for everybody.
But you can't make.
You can't put a, um, you can't make an object, one of one of the objects properties on for some players
and off for other players.
The only way to do that is to have the one object for each player.
Okay.
Which is basically why I guess duplicates over.
But again, if you don't understand that just yet, that's fine.
It's just a basic introduction to that.
But that will all be explained later in some later topics as well.
Um, but the idea I'm trying to explain, basically, is anything you put inside a starter player's
scripts gets moved over inside of the player.
Okay.
So let's add a local script inside of starter player scripts.
Okay, now you will use a local script whenever you're talking about the player or player guys okay.
So whenever you even start talking about the player or guys, you will be using a local script, okay.
Um, 99.99% of the time when you even type guy or player, it will be in a local script.
Okay, so make sure you're using the right script for this one.
So one key difference with the local scripts is that it exists for each player.
We know that because it gets duplicated over two player scripts when the player joins.
So if you write one local script and you have 30 players, that means you have 30, 30 local scripts
running because they're running for each individual player.
Okay.
Um, this means it's quite easy to reference the player.
Okay.
Um, so to reference the player, um, which to do that.
So, yeah, to reference the player, um, you'd reference what's called the local player.
And the local player is the player which the local script is running for.
So what this local script is inside of.
So to reference the local player you would write the local keyword for variable player is equal to game
dot players, dot local player okay.
And the description there you can see the player that the local script is running for.
Okay.
And that is how you would reference the player in a local script.
Now that is very, very useful actually because referencing players can.
Has to be quite difficult if you try to think about it, because players join randomly with different
usernames, which you can't predict.
So there's lots of unpredictability involved in referencing the player, which is why using the local
player is the best method to do it, and it's actually very quick and easy to do.
Now, don't try this in a server script because it won't work, because a server script makes changes
on the server.
And if there are 30 players in the game, there is only one server script, but there are 30 local scripts,
one for each player.
Okay, so that is how you reference the player.
And from there you can go ahead and reference some of its properties, such as its camera max and minimum
zoom, its team, its health display distance or how far away will it display its health and all kind
of properties.
Okay, I'd really recommend that you try out and look through some of these.
But again, this is something that we will look at later on.
This is just a very basic introduction to local scripts.
Okay.
Um, however, if you want to get to character when you think about it, it is is also quite difficult.
Okay.
Um, because again, the character, even though it has the same name as the player, the player can
have any username and they can join at any time, like with the character.
Um, what makes it even more difficult though, is the player loads much quicker than the character
because the character has things like a humanoid, which takes a lot longer to set up and load um,
for.
In Roadblock Studio, the character takes one one between anywhere between 1 and 2 seconds to load after
the player loads.
So, um, if you were to somehow get the try to reference the character straight away, it would.
It wouldn't work.
Okay.
Um, so it's quite it's quite difficult area, um, to write code.
Um, so how you actually do it is, um, well, how you actually do it, we would learn that later on.
Um, but we're going to put a bit of a placeholder in here for now.
So we are going to put a wait function for about two seconds.
Okay.
And this will give the character enough time to load so that we can reference it.
Okay.
Um, for an actual game, you wouldn't want to write this because, um, what if the couch takes longer
than two seconds to load?
Then none of your scripts will work for it.
Okay, um, so we're putting in there as a placeholder.
But we will come back to this later on.
Again, this is just a basic introduction, okay?
We will come back to all this stuff later on and explain the better ways to do it.
Okay, so let's say that we are now sure that the character has loaded into the game to reference the
character.
It's actually very simple.
The player has a property called character, and once the character is loaded, the character model
object will exist in here.
So we can reference it by saying local character is literally just by saying player dot character.
Okay.
And that will then reference the character in your workspace.
Okay.
So this these two rays of referencing.
So getting the player through Gameplayers dot local player.
Then for us at the moment putting a wait two seconds is a placeholder.
But again we won't have to do that later on.
And then referencing the character using player dot character makes all this difficult.
Scripting with unknown names and unknown times when it will exist.
Much simpler.
Okay, so let's have a look and see what we can do with this, as now we've referenced the character,
we can actually change a bunch of its properties.
So let's look at a character and we're going to have a go at changing some of its body parts to be different
material.
We're basically going to make my entire my entire character here, um, exist as like a force field
kind of material.
So it'll look very look almost invisible, basically.
Almost like if you don't an invisibility potion or something like that.
Okay.
Um, so we have we know how to reference this model here, and all of the body parts exist in that model.
So you can very easily get all of its body parts here.
Now, um, this is where it gets a bit more complicated as well, because I have a head, left foot,
left hand, left lower arm, and all this other stuff.
In total, I have 15 body parts.
Okay.
Some characters have 15 body parts.
Other characters have six body parts.
Okay.
If a character has 15 body parts, it is classed as AR 15.
If it has six body parts, it's classed as R6.
If you play Roblox a lot, you might already know that.
Um, so this means that, um, if you're referencing some of these body parts, they will be different
depending if it's r six or R 15.
Okay.
Now I'm just going to change a couple.
So my model here is AR 15.
I'm going to change some of the AR 15 body parts.
But do check and make sure your model your character is not R six because if it is you'll have different
ones to change.
Okay, so let's have a go at changing the the head.
So let's write character dot head.
And here's where autocorrect will not work because it doesn't currently exist.
So it can't check what to go from there.
So you will have to remember the properties.
Okay.
It has a property called material and you can set that to enum dot material dot force field.
Okay.
I'm also going to change it change its upper and lower torso.
So character dot upper torso.
It might even be good idea to take a picture of your character's body parts in the explorer, so you
know what they're all called dot material is equal to again enum dot material, dot force field, and
then finally character dot lower torso.
Dot material is equal to enum dot material dot force field.
Okay.
And let's go ahead and play the game and see what our character looks like.
And you can see here that my head has disappeared here.
It's still there.
But you can you can just about see the outline of it.
But this is the force field material for you and hopefully you could see as well.
When was loaded into the game that my torso was also invisible.
It's very difficult to see though.
Oh, you can just about see it there, but it's very difficult to see because of my clothing covering
it.
Um, but yeah, so that's an example about how you can kind of apply everything you already know onto
characters.
So this is very this is really where the application aspect really comes in.
Okay.
Um, you can you now know how to get the character in a roundabout placeholder way.
Okay.
You'll learn how a better way later on.
But this is the way you know how to start off with.
Okay, um, now you know how to do that.
Um, you can change all of the properties of the character and play around with all that kind of stuff.
So, um, make sure you have a play around of that, as there's quite a lot to learn there.
But as long as you follow the start bits, you'll find the character and we play it quite easily.
Then it's just an application of what you already know.
Okay, so make sure you have a play around with that.
And um, make sure also that you're confident with some of the other areas we've looked at recently.
Because next lesson we're going to start a whole new area called functions, which will take a couple
of lessons, but they'll be very useful for you to know.
So make sure that you're confident and ready for the next lecture.